﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPPEI.Coolzon.Common
{
    /// <summary>
    /// 转换器
    /// </summary>
    public static class Convertor
    {
        /// <summary>
        /// 将字符串转化为double，转换失败返回0
        /// </summary>
        /// <param name="valueString"></param>
        /// <returns></returns>
        public static double ToDouble(string valueString)
        {
            return ToDouble(valueString, 0);
        }

        /// <summary>
        /// 将字符串转化为double，转换失败返回默认值
        /// </summary>
        /// <param name="valueString"></param>
        /// <param name="defaultValue">默认值</param>
        /// <returns></returns>
        public static double ToDouble(string valueString, double defaultValue)
        {
            double value = 0;
            if (double.TryParse(valueString, out value))
            {
                return value;
            }
            return defaultValue;
        }
    }
}
